package com.fh.utils;/**
 * 描述:
 * Author:袁亚强
 * Date:2021/12/1218:03
 */

import com.fh.user.entity.vo.User;
import com.fh.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * created by macro on 2021/12/12,
 */
@Component
public class Test {
    @Autowired
    private UserService userService;

    // 每天 8:30 执行一次
    @Scheduled(cron = "0 50 8 * * ?")
    public void quartzTest() throws Exception {
        List<User> users = this.userService.queryUser();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

        for (User u : users) {
            String format = sdf.format(u.getCreateDate());

            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
            String today = sdf2.format(new Date());

            int i = (Integer.parseInt(today) - Integer.parseInt(format));
            System.out.println(i);
            if (i%3 == 0) {
                EmailUtils.sendMail(u.getEmail(), "恭贺", "恭喜您该交网费了!!!!");
                System.out.println("发送成功");
            }
        }

    }
}
